package core.query;

import core.query.filter.ContainFliter;
import core.query.filter.EqualsFilter;
import core.query.filter.GreatThanEqualsFilter;
import core.query.filter.GreatThanFilter;
import core.query.filter.ISqlFilter;
import core.query.filter.LeftLikeFilter;
import core.query.filter.LessThanEqualsFilter;
import core.query.filter.LessThanFilter;
import core.query.filter.NotContainFliter;
import core.query.filter.NotEqualsFilter;
import core.query.filter.NotLeftLikeFilter;
import core.query.filter.NotRightLikeFilter;
import core.query.filter.RightLikeFilter;

public class FilterFactory {

	public static ISqlFilter createFilter(QueryRule rule) {
		if (rule == null) {
			return null;
		}
		if (rule.getData() == null) {
			return null;
		}
		if ("eq".equals(rule.getOp())) {
			return new EqualsFilter(rule.getField(), rule.getData());
		}
		if ("ne".equals(rule.getOp())) {
			return new NotEqualsFilter(rule.getField(), rule.getData());
		}
		if ("lt".equals(rule.getOp())) {
			return new LessThanFilter(rule.getField(), rule.getData());
		}
		if ("le".equals(rule.getOp())) {
			return new LessThanEqualsFilter(rule.getField(), rule.getData());
		}
		if ("gt".equals(rule.getOp())) {
			return new GreatThanFilter(rule.getField(), rule.getData());
		}
		if ("ge".equals(rule.getOp())) {
			return new GreatThanEqualsFilter(rule.getField(), rule.getData());
		}
		if ("bw".equals(rule.getOp())) {
			return new RightLikeFilter(rule.getField(), rule.getData());
		}
		if ("bn".equals(rule.getOp())) {
			return new NotRightLikeFilter(rule.getField(), rule.getData());
		}
		if ("ew".equals(rule.getOp())) {
			return new LeftLikeFilter(rule.getField(), rule.getData());
		}
		if ("en".equals(rule.getOp())) {
			return new NotLeftLikeFilter(rule.getField(), rule.getData());
		}
		if ("cn".equals(rule.getOp())) {
			return new ContainFliter(rule.getField(), rule.getData());
		}
		if ("nc".equals(rule.getOp())) {
			return new NotContainFliter(rule.getField(), rule.getData());
		} else {
			throw new IllegalArgumentException("错误的参数");
		}
	}
}
